package com.tcu.oss.controller;

import com.tcu.oss.service.IOss;
import com.tcu.result.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/picture")
public class OssController {
    private IOss oss;

    @Autowired
    public void setOss(IOss oss) {
        this.oss = oss;
    }
    @PostMapping("/upload")
    public R uploadFile(MultipartFile file){
        String imgPath = oss.uploadFile(file);
        return R.success().data("imgPath", imgPath);
    }
    @PostMapping("/deleteByName")
    public R deleteFile(@RequestBody String fileName){
        Boolean aBoolean = oss.deleteFileByFileName(fileName);
        return aBoolean ? R.success() : R.error();
    }

}
